/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pa165.dominating.species.tos;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
 *
 * @author Filip Dinh
 */
public class AnimalTo implements Serializable {

    private static final long serialVersionUID = 1L;
    private Long id;
    private String species;
    private String name;
    private EnvironmentTo environmentTo;
    private Set<AnimalTo> preyTo;

    public Long getId() {
        return id;
    }

    public String getSpecies() {
        return species;
    }

    public String getName() {
        return name;
    }

    public void addPrey(AnimalTo prey) {
        if (preyTo == null) {
            preyTo = new HashSet<>();
        }
        this.preyTo.add(prey);
    }

    public void removePrey(AnimalTo prey) {
        if (preyTo == null) {
            throw new IllegalStateException("Cannot remove prey from non existing list of preys.");
        }
        this.preyTo.remove(prey);
    }

    public EnvironmentTo getEnvironmentTo() {
        return environmentTo;
    }

    public Set<AnimalTo> getPreyTo() {
        return preyTo;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public void setSpecies(String species) {
        this.species = species;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setEnvironmentTo(EnvironmentTo environmentTo) {
        this.environmentTo = environmentTo;
    }

    public void setPreyTo(Set<AnimalTo> preyTo) {
        this.preyTo = preyTo;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final AnimalTo ani = (AnimalTo) obj;
        if (this.getId() != ani.getId() && (this.getId() == null || !this.getId().equals(ani.getId()))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        return id + ", " + name;
    }
}
